package com.selune.online.ordering.system.project.tenant.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.selune.online.ordering.system.project.api.base.response.Response;
import com.selune.online.ordering.system.project.api.pojo.user.customer.dto.CustomerUserSearchDTO;
import com.selune.online.ordering.system.project.api.pojo.user.customer.vo.CustomerUserInfoVO;
import com.selune.online.ordering.system.project.api.pojo.user.tenant.vo.TenantUserInfoVO;
import com.selune.online.ordering.system.project.api.service.user.IUserManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @author xiaoyp
 * @date 2020/3/23
 * <p>
 * Description:
 */

@RestController
@RequestMapping("/api/v1/ordering/manage/user")
@Slf4j
@Api(value = "商户用户接口")
public class TenantUserManageController {
	
	@Autowired
	private IUserManageService iUserManageService;
	
	@ApiOperation(value = "根据用户名查找用户", notes = "根据用户名查找用户")
	@ApiImplicitParam(name = "userName", value = "用户名", required = true, dataType = "String", paramType = "query")
	@GetMapping(value = "/customer/info/{userName}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<CustomerUserInfoVO> selectOneUser(@PathVariable("userName") String userName) {
		return iUserManageService.selectOneCustomerUser(userName);
	}
	
	@ApiOperation(value = "查询所有消费者用户", notes = "查询所有消费者用户")
	@ApiImplicitParam(name = "customerUserSearchDTO", value = "搜索条件", dataType = "CustomerUserSearchDTO", paramType = "query")
	@GetMapping(value = "/customer/list", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<List<CustomerUserInfoVO>> selectAllCustomerUser(CustomerUserSearchDTO customerUserSearchDTO) {
		return iUserManageService.selectAllCustomerUser(customerUserSearchDTO);
	}
	
	@ApiOperation(value = "消费者用户分页", notes = "消费者用户分页")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "current", value = "页码", dataType = "Integer", paramType = "query"),
		@ApiImplicitParam(name = "size", value = "每页大小", dataType = "Integer", paramType = "query"),
		@ApiImplicitParam(name = "customerUserSearchDTO", value = "搜索条件", dataType = "CustomerUserSearchDTO", paramType = "query")
	})
	@GetMapping(value = "/customer/page", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Page<CustomerUserInfoVO>> pageCustomerUser(@RequestParam(required = false, defaultValue = "1") Integer current,
	                                                           @RequestParam(required = false, defaultValue = "10") Integer size,
	                                                           CustomerUserSearchDTO customerUserSearchDTO) {
		return iUserManageService.pageAllCustomerUser(current, size, customerUserSearchDTO);
	}
	
	@ApiOperation(value = "删除消费者用户", notes = "删除消费者用户")
	@ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long", paramType = "query")
	@DeleteMapping(value = "/customer/delete/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> deleteCustomerUserById(@PathVariable("userId") Long userId) {
		return iUserManageService.deleteCustomerUserById(userId);
	}
	
	@ApiOperation(value = "批量删除消费者用户", notes = "批量删除消费者用户")
	@ApiImplicitParam(name = "userIds", value = "用户ids", required = true, dataType = "List", paramType = "query")
	@DeleteMapping(value = "/customer/delete/batch", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> deleteCustomerUserByIds(List<Long> userIds) {
		return iUserManageService.deleteCustomerUserByIds(userIds);
	}
	
	
	@ApiOperation(value = "根据用户名查找用户", notes = "根据用户名查找用户")
	@ApiImplicitParam(name = "tenantName", value = "用户名", required = true, dataType = "String", paramType = "query")
	@GetMapping(value = "/tenant/info/{userName}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<TenantUserInfoVO> selectOneTenantUser(@PathVariable("userName") String tenantName) {
		return iUserManageService.selectOneTenantUser(tenantName);
	}
	
	@ApiOperation(value = "查询所有商户用户", notes = "查询所有商户用户")
	@GetMapping(value = "/tenant/list", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<List<TenantUserInfoVO>> selectAllTenantUser() {
		return iUserManageService.selectAllTenantUser();
	}
	
	@ApiOperation(value = "商户用户分页", notes = "商户用户分页")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "current", value = "页码", dataType = "Integer", paramType = "query"),
		@ApiImplicitParam(name = "size", value = "每页大小", dataType = "Integer", paramType = "query")
	})
	@GetMapping(value = "/tenant/page", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	Response<Page<TenantUserInfoVO>> pageAllTenantUser(@RequestParam(required = false, defaultValue = "1") Integer current,
	                                                   @RequestParam(required = false, defaultValue = "10") Integer size) {
		return iUserManageService.pageAllTenantUser(current, size);
	}
	
	@ApiOperation(value = "删除商户用户", notes = "删除商户用户")
	@ApiImplicitParam(name = "tenantId", value = "用户id", required = true, dataType = "Long", paramType = "query")
	@DeleteMapping(value = "/tenant/delete/{tenantId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> deleteTenantUserById(@PathVariable("tenantId") Long tenantId) {
		return iUserManageService.deleteTenantUserById(tenantId);
	}
	
	@ApiOperation(value = "批量删除商户用户", notes = "批量删除商户用户")
	@ApiImplicitParam(name = "tenantIds", value = "用户id", required = true, dataType = "List", paramType = "query")
	@DeleteMapping(value = "/tenant/delete/batch", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> deleteTenantUserByIds(List<Long> tenantIds) {
		return iUserManageService.deleteTenantUserByIds(tenantIds);
	}
}
